<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="./../../template/tagedu.xhtml">

    <ui:define name="title">
        <title><h:outputText value="Criar Termo de Consentimento - TAG"/></title>
    </ui:define>
    
    <ui:define name="content">
        <h:outputText styleClass="enrollmentName" value="Criar Termo de Consentimento"/> 
        <h:form id="createConsentForm"> 
            <p:messages id="message" autoUpdate="true" showDetail="true"/>
            <h:panelGroup id="details" >
                
                <div class="input-list">
                <h:outputLabel styleClass="label" value="Ano: "/>
                <p:spinner value="#{consentTermBean.year}" min="#{consentTermBean.actualYear-1}"
                           max="#{consentTermBean.actualYear}" size="4">
                    <f:validator validatorId="yearV"/>
                    <f:attribute name="minimo" value="#{(generateTermBean.actualYear-1).toString()}"/>
                    <f:attribute name="maximo" value="#{(generateTermBean.actualYear).toString()}"/>
                    <p:ajax update="unity" process="@this"/>
                </p:spinner><br/>
                </div>
                <div class="input-list">
                <h:outputLabel  styleClass="label" for="unity" value="Turma: "/>
                <p:selectOneMenu id="unity" value="#{consentTermBean.unity}" converter="unityC" >
                    <f:selectItem value="#{null}" itemLabel="Selecione uma unidade:"/>
                    <f:selectItems value="#{generateTermBean.unityList}" var="u" itemLabel="#{u.name}" itemValue="#{u}" />
                    <f:validator validatorId="unityV"/>
                    <p:ajax update="bottomCreatePDF " process="@this"/>
                </p:selectOneMenu>
                </div>
                
                <div class="clear"></div>

                <p:separator/>

                <p:commandButton id="bottomCreatePDF" action="#{generateTermBean.loadHumanList()}"
                        value="Carregar" disabled="#{generateTermBean.unity == null}"
                        oncomplete="PF('humanCheckList').show()" update=":listF"/>                
            </h:panelGroup>
        </h:form>
    </ui:define>
    <ui:define name="modals">
        <p:dialog header="Alunos a Consentir:" widgetVar="humanCheckList" resizable="false" modal="true" >
            <h:form id="listF">  
                <p:scrollPanel style="width:300px;height:300px">
                    <p:selectManyCheckbox value="#{generateTermBean.selectedHumans}" converter="humanC"  
                            layout="pageDirection"> 
                        <f:selectItems value="#{generateTermBean.activateds}" var="human"
                                       itemValue="#{human}" itemLabel="#{human.name}" itemDisabled="#{human.age le 2}" />  
                    </p:selectManyCheckbox>   
                    <br/><br/>
                </p:scrollPanel>
                <p:commandButton id="submitButton" value="Gerar" 
                         action="#{generateTermBean.generate()}" ajax="false"
                         onclick="PF('humanCheckList').hide(); this.form.target='_blank'"/>  
            </h:form> 
        </p:dialog>
    </ui:define>
</ui:composition>